package Q150

import java.util.*

class Main {

}

fun main() {

}

//逆波兰表达式求值
class Solution {
    fun evalRPN(tokens: Array<String>): Int {
        val stack: Deque<Int> = LinkedList()
        for (i in tokens.indices) {
            if ("+" == tokens[i]) {
                stack.push(stack.pop() + stack.pop())
            } else if (tokens[i] == "-") {
                stack.push(-stack.pop() + stack.pop())
            } else if ("*" == tokens[i]) {
                stack.push(stack.pop() * stack.pop())
            } else if ("/" == tokens[i]) {
                val temp1 = stack.pop()
                val temp2 = stack.pop()
                stack.push(temp2 / temp1)
            } else {
                stack.push(Integer.valueOf(tokens[i]))
            }
        }
        return stack.pop()
    }
}